package com.zsgl.dao;

import java.util.List;
import java.io.Serializable;
import com.zsgl.domain.HotelAddress;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.beans.factory.annotation.Autowired;

public class HotelAddressDAOImpl implements HotelAddressDAO {
	
	private HibernateTemplate template;
	
	@Autowired
	public HotelAddressDAOImpl(HibernateTemplate template) {
		this.template = template;
	}
	
	public HibernateTemplate getTemplate() {
		return template;
	}
	
	public HotelAddress create() {
		return new HotelAddress();
	}
	
	public HotelAddress save(HotelAddress obj) {
		template.save(obj);
		return obj;
	}

	public void delete(HotelAddress obj) {
		template.delete(obj);
	}
	
	public void update(HotelAddress obj) {
		template.update(obj);
	}
	
	public HotelAddress find(Serializable id) {
		return template.get(HotelAddress.class, id);
	}
	
	@SuppressWarnings("unchecked")
	public List<HotelAddress> findAll() {
		return (List<HotelAddress>)template.find("from HotelAddress");
	}
	
	@SuppressWarnings("unchecked")
	public List<HotelAddress> find(int firstResult, int maxResult) {
		return template.findByCriteria(DetachedCriteria.forClass(HotelAddress.class), firstResult, maxResult);
	}
	
	public long count() {
		return (Long)template.find("select count(o) from HotelAddress o").listIterator().next();
	}
}